<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <div class="top-title">快速查询</div>
          <el-input v-model="txtsearch" placeholder="药物组合代码|名称|输入码" @keyup.enter.native="filterQuery" style="width:240px"></el-input>
          <div class="top-button">
              <el-button @click="btnQuery" icon="el-icon-search" type="primary" v-has="'PINQUERY'" :disabled="bChangeFlag">查询</el-button>
              <el-button @click="btnAdd" icon="el-icon-plus" v-has="'PADD'" :disabled="bChangeFlag">新增</el-button>
              <el-button @click="btnDel" icon="el-icon-delete" v-has="'PDELETE'" :disabled="bChangeFlag">删除</el-button>
              <el-button @click="btnSave" icon="el-icon-document" v-has="'PMODIFY'" :disabled="!bChangeFlag">保存</el-button>
              <el-button @click="btnClear" icon="el-icon-close" :disabled="!bChangeFlag">取消</el-button>
              <el-button @click="btnExport" icon="el-icon-upload2" :disabled="bChangeFlag">导出</el-button>
          </div>
      </div>
      <div class="pagecenter">
          <rm-layout-right splitcolor="#DoderBlue" movingcolor="#CCFFFF" :splitwidth="5" :fixsize="730">
              <template v-slot:fix>
                  <div v-loading="bPageInitLoading" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" style="height:100%">
                      <rm-layout-top splitcolor="#DoderBlue" movingcolor="#CCFFFF" :splitwidth="5" :fixsize="130" :canDrag="false">
                          <template v-slot:fix>
                              <div style="height:130px;border:1px solid #CCC">
                                  <el-form :label-position="labelPosition" label-width="80px" :model="detailData">
                                      <table class="table1style" style="width:100%;font-size:12px">
                                          <tr>
                                              <td align="right" style="color:#F56C6C">药物组合代码</td>
                                              <td>
                                                  <el-input v-model="detailData.medgroupcode" @input="HasChange" :readonly="actionindex == 'M'" @change="ChkKeyId" ref="input0" @keyup.enter.native="NextFocus(0)"></el-input>
                                              </td>
                                              <td align="right">序号</td>
                                              <td>
                                                  <el-input v-model="detailData.seq" @input="HasChange" ref="input1" @keyup.enter.native="NextFocus(1)"></el-input>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right" style="color:#F56C6C">药物组合名称</td>
                                              <td>
                                                  <el-input v-model="detailData.medgroupname" @input="HasChange" @change="CreateInputcode" ref="input2" @keyup.enter.native="NextFocus(2)"></el-input>
                                              </td>
                                              <td align="right">输入码</td>
                                              <td>
                                                  <el-input v-model="detailData.inputcode" @input="HasChange" ref="input3" @keyup.enter.native="NextFocus(3)"></el-input>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right">组合类型</td>
                                              <td>
                                                  <el-select v-model="detailData.groupkind" style="width:100%" @change="HasChange" ref="input4" @keyup.enter.native="NextFocus(4)">
                                                      <el-option v-for="(item,index) in $opt.groupKindOptions" :key="index" :label="item.label" :value="item.value">
                                                      </el-option>
                                                  </el-select>
                                              </td>
                                              <td align="right">打印标签</td>
                                              <td>
                                                  <el-checkbox ref="input5" @keyup.enter.native="NextFocus(5)" true-label="1" false-label="0" v-model="detailData.printbar" @change="HasChange"></el-checkbox>
                                              </td>
                                          </tr>
                                          <tr>
                                              <td align="right">
                                                  应用方法
                                              </td>
                                              <td>
                                                  <el-select v-model="detailData.appmethod" ref="input6" @keyup.enter.native="NextFocus(6)" @change="appmethodChange" style="width:100%">
                                                      <el-option :key="index" :label="item.label" :value="item.value" v-for="(item,index) in $opt.appmethodOption" clearable></el-option>
                                                  </el-select>
                                              </td>
                                              <td align="right">仪器板条代号</td>
                                              <td>
                                                  <el-input ref="input7" @keyup.enter.native="NextFocus(7)" v-model="detailData.panelno" @input="HasChange"></el-input>
                                              </td>
                                          </tr>
                                      </table>
                                  </el-form>
                              </div>
                          </template>
                          <div style="height:100% ;width:100%;background-color:#ddccbb;" class="detailxTable">
                              <vxe-table :data="rXTableData" :loading="bLoading" :keyboard-config="selKeyConfig" :keyboard-local-config="selKeyLocalConfig" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{
              trigger: 'click',
              mode: 'cell',
              showStatus: true,
              activeMethod: ActiveMethod,
              showIcon: false,
            }" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="rXTable" resizable size="mini" stripe :row-class-name="rRowClassName" :cell-class-name="rCellClassName" :edit-closed="rEditClosed" :mouse-config="{selected: true}" show-header-overflow="tooltip" show-overflow="tooltip">
                                  <vxe-table-column field="med" title="药物代码(双击弹窗)" width="160" :edit-render="{name: 'input',autoselect: true,}">
                                      <template v-slot:header="{column}">
                                          <span style="color:#F56C6C;">药物代码(双击弹窗)</span>
                                      </template>
                                      <template v-slot:edit="{row}">
                                          <el-input v-model="row.med" style="width:100%" placeholder="" @keyup.space.native="popGetRow(row);" @dblclick.native="popGetRow(row)" readonly>
                                          </el-input>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="seq" title="序号" width="40" align="center" :edit-render="{
                name: 'input',
                autoselect: true,
                events: {change: HasChange},
              }"></vxe-table-column>
                                  <vxe-table-column field="loadresultflag" title="默认结果标志" width="130" :edit-render="{
                name: 'select',
                options:ResultFlagOptions,
                events:{change:(row,val) => {row.row.loadresultflag = val.target.value;row.row.defaultresult = val.target.options[val.target.options.selectedIndex].text;HasChange()}},
              }"> </vxe-table-column>
                                  <vxe-table-column field="defaultrad" title="默认RAD" width="60" :edit-render="{
                name: 'input',
                autoselect: true,
                events: {change: HasChange},
              }">
                                  </vxe-table-column>
                                  <vxe-table-column field="defaultmic" title="默认MIC" width="60" :edit-render="{
                name: 'input',
                autoselect: true,
                events: {change: HasChange},
              }">
                                  </vxe-table-column>
                                  <vxe-table-column field="defaultresult" title="默认结果" width="120" :edit-render="{
                name: 'input',
                autoselect: true,
                events: {change: HasChange},
              }">
                                  </vxe-table-column>
                                  <vxe-table-column field="medmethod" title="试验方法" :edit-render="{name: 'input', autoselect: true}" width="80">
                                      <template v-slot:edit="{ row,rowIndex}">
                                                  <el-select v-model="row.medmethod" @change="medmethodChange(row)" placeholder="请选择"  popper-class="mini-select" style="width: 100%;">
                                                      <el-option v-for="item in $opt.appmethodOption" :key="rowIndex + item.value" :label="item.label" :value="item.value"></el-option>
                                                  </el-select>
                                              </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="etestflag" title="ETEST标志" width="70" align="center">
                                      <template v-slot="{row}">
                                          <el-checkbox v-model="row.etestflag" @change="HasChange" true-label="1" false-label="0" :disabled="etesteditflag"></el-checkbox>
                                      </template>
                                  </vxe-table-column>
                                  <template v-slot:fix>
                                      <div style="font-size:17px;padding:3px;background-color:#fff;text-align:center;font-weight:bold">
                                          <el-button @click="btnDetailAdd()" class="el-button--310">新增明细</el-button>
                                          <el-button @click="btnDetailDel()" class="el-button--310">删除明细</el-button>
                                      </div>
                                  </template>
                              </vxe-table>
                              <!-- <div class="detail-operation">
                                      <el-button icon="el-icon-plus" class="el-button--310"  @click.native="btnDetailAdd">新增明细</el-button>
                                      <el-button icon="el-icon-delete" class="el-button--310"  @click.native="btnDetailDel">删除明细</el-button>
                                      </div> -->
                          </div>
                      </rm-layout-top>
                  </div>
              </template>
              <div style="height:100%">
                  <vxe-table :data.sync="showLXTableData" :loading="bLoading" :keyboard-local-config="keyLocalConfig" :row-class-name="lRowClassName" :select-config="selectConfig" :sort-config="{trigger: 'cell'}" :edit-config="{
          trigger: 'click',
          mode: 'cell',
          showStatus: true,
          showIcon: false,
        }" @current-change="CurrentChangeEvent" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column ref="lXTable" resizable size="mini" stripe show-header-overflow="tooltip" show-overflow="tooltip">
                      <vxe-table-column field="seq" title="序号" width="40" align="center"></vxe-table-column>
                      <vxe-table-column field="medgroupcode" title="药物组合代码" width="120"></vxe-table-column>
                      <vxe-table-column field="medgroupname" title="药物组合名称" width="160"></vxe-table-column>
                      <vxe-table-column field="appmethod" title="应用方法" width="80" align="center"></vxe-table-column>
                      <vxe-table-column field="inputcode" title="输入码" width="120"></vxe-table-column>
                      <vxe-table-column field="groupkind" align="center" title="组合类型" width="80"></vxe-table-column>
                      <vxe-table-column field="printbar" title="打印标签" width="80" align="center">
                          <template v-slot="{row}">
                              <el-checkbox v-model="row.printbar" true-label="1" false-label="0" :disabled="true"></el-checkbox>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="panelno" title="仪器板条代号" width="120"></vxe-table-column>
                  </vxe-table>
              </div>
          </rm-layout-right>
          <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="抗生素选择" :visible.sync="bPopLabMed" v-if="bPopLabMed" :keyboard-local-config="keyLocalConfig"  >
              <rm-pop-common @change="LabMedRowChanges" @cancel="bPopLabMed = false" datatype="labmed" :multiple="true" :stopflag="stopflag" ></rm-pop-common>
          </el-dialog>
      </div>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS821",
  data() {
      return {
          txtsearch: "",
          actionindex: "M",
          labelPosition: "right",
          bLoading: false,
          bChangeFlag: false,
          bPopLabMed: false,
          bPageInitLoading: false,
          selKeyConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
          },
          selKeyLocalConfig: {
              isArrow: true,
          },
          keyLocalConfig: {
              isDel: true,
              isTab: true,
              isEdit: true,
              isArrow: true,
          },
          detailData: {
              medgroupcode: "",
              medgroupname: "",
              seq: 0,
              defpanelno: "",
              appmethod: "",
          },
          selectConfig: { tigger: "row" },
          labMedRow: {},
          tempmed: {},
          tmpdetailData: {},
          selrow: [],
          AddData: [], //新增数据 用于变色
          ModData: [], //修改数据 用于变色
          lXTableData: [],
          rXTableData: [],
          showLXTableData: [],
          etesteditflag: false,
          stopflag:"1",
          medresultList:[],
          ResultFlagOptions:[],
      };
  },
  created() {
      this.btnQuery();
  },
  mounted(){
      this.getMedResultList();
  },
  computed: {
      //排序
      autoSeq() {
          let len = this.$refs.rXTable.tableData.length;
          return (len + 1) * 10;
      },
  },
  methods: {
      //----------------- 查询类 ----------------- //
      //主表查询
      filterQuery() {
          let filterName = this.txtsearch.trim();
          if (filterName) {
              let rest = this.lXTableData.filter((item) => {
                  return item.medgroupcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1 || (item.inputcode ? item.inputcode.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false) || (item.medgroupname ? item.medgroupname.toUpperCase().indexOf(filterName.toUpperCase()) > -1 : false);
              });
              this.showLXTableData = rest;
          } else {
              this.showLXTableData = this.lXTableData;
          }
          let row = this.showLXTableData[0];
          if (row) {
              this.HightLightRow(row);
          } else {
              this.HightLightRow(false);
          }
      },
      getMedResultList(){
          this.$ddldata.getMedResultList().then((data) =>{
              this.medresultList=data;
              if(this.medresultList && this.medresultList.length>0){
                  this.ResultFlagOptions=[];
                  this.medresultList.forEach(element => {
                      var item={value:element.value , label:element.name};
                      this.ResultFlagOptions.push(item);
                      
                  });
              }else{
                  this.ResultFlagOptions=this.$opt.loadResultFlagOptions;
              }
          })
      },
      btnQuery() {
          this.AddData = [];
          this.ModData = [];
          this.bLoading = true;
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS821",
                  method: "post",
                  data: {
                      action: "lab_medgroup_query",
                  },
              })
              .then((res) => {
                  this.lXTableData = res.data;
                  // this.showLXTableData=XEUtils.clone(this.lXTableData,true)
                  this.filterQuery();
                  if (this.lXTableData.length == 0) this.actionindex = "A";
                  // this.HightLightRow(this.showLXTableData[0]);
                  this.bLoading = false;
              })
              .catch((e) => {
                  this.ErrorCatch(e, "", "error");
                  this.bLoading = false;
              });
      },
      //明细查询 -- 主表，子表
      async detailQuery(row) {
          try {
              this.selrow = row;
              this.actionindex = "M";
              this.bPageInitLoading = true;
              const res = await this.$tool.request({
                  url: "LIS/LIS8/LIS821",
                  method: "post",
                  data: {
                      action: "lab_medgroup_query_detail",
                      medgroupcode: row.medgroupcode,
                  },
              });
              if (res.labmedgroup.length > 0) {
                  this.detailData = res.labmedgroup[0];
                  this.rXTableData = res.labmedgroupdetail;
              } else {
                  this.detailData = {};
                  this.rXTableData = [];
              }
              this.tmpdetailData = XEUtils.clone(this.detailData, true);
              this.bPageInitLoading = false;
          } catch (e) {
              this.ErrorCatch(e, "", "error");
              this.bPageInitLoading = false;
          }
      },
      //主键查询  是否重复
      ChkKeyId() {
          this.$tool
              .request({
                  url: "LIS/LIS8/LIS821",
                  method: "post",
                  data: {
                      action: "lab_medgroup_chkkeyid",
                      medgroupcode: this.detailData.medgroupcode,
                  },
              })
              .then((res) => {
                  if (res == "1") {
                      this.$alert("药物组合代码重复，请重新填写！");
                      this.$refs.input0.focus();
                  }
              })
              .catch((e) => {
                  this.ErrorCatch(e, "", "error");
              });
      },
      //----------------- 按钮类 -----------------//
      //新增
      btnAdd() {
          this.bChangeFlag = true;
          this.actionindex = "A";
          this.detailData = {
              medgroupcode: "",
              medgroupname: "",
              lathname: "",
              instrno: "",
              inputcode: "",
              seq: "",
              groupkind: "1",
              printbar: "0",
              panelno: "",
              defpanelno: "",
          };
          this.rXTableData = [];
          this.$refs.input0.focus();
      },
      btnDetailAdd() {
          this.$refs.rXTable.insertAt(
              {
                  medgroupcode: this.detailData.medgroupcode,
                  seq: this.autoSeq,
                  etestflag: "0",
              },
              -1
          );
          this.$refs.rXTable.setActiveRow(this.$refs.rXTable.tableData[this.$refs.rXTable.tableData.length - 1], "med");
          this.$refs.rXTable.scrollToRow(this.$refs.rXTable.tableData[this.$refs.rXTable.tableData.length - 1]);
          this.bChangeFlag = true;
      },
      btnDetailDel() {
          // this.$refs.rXTable.remove(this.$refs.rXTable.getCurrentRow()),
          //                 this.bChangeFlag = true
          try {
              var delrow = this.$refs.rXTable.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.rXTable.tableData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.rXTable.remove(delrow);
                  let havedata = this.$refs.rXTable.tableData;
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.rXTable.setCurrentRow(selectrow);
                  } else {
                      this.$refs.rXTable.setCurrentRow(null);
                  }
                  this.bChangeFlag = true;
              }
          } catch (e) {
              console.log("error", e);
          }
      },
      //删除 -- 弹窗提示
      btnDel() {
          var delrow = this.$refs.lXTable.getCurrentRow();
          this.$confirm('确定删除药物组合名称为<b style="color:red">' + delrow.medgroupname + "</b>的记录吗？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              dangerouslyUseHTMLString: true,
              type: "warning",
          })
              .then(() => {
                  this.actionindex = "D";
                  this.confirmDel();
              })
              .catch((e) => {
                  this.$message({
                      type: "info",
                      message: "已取消删除",
                  });
              });
      },
      //删除 -- 确认删除
      async confirmDel() {
          try {
              var delrow = this.$refs.lXTable.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.lXTable.tableData;
                  var rowindex = alld.indexOf(delrow);
                  await this.btnSave().then(() => {
                      this.$refs.lXTable.remove(delrow);
                      this.lXTableData.splice(rowindex, 1);
                      let havedata = this.$refs.lXTable.tableData;
                      if (havedata.length > 0) {
                          if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                          let selectrow = havedata[rowindex];
                          this.HightLightRow(selectrow);
                      } else {
                          this.HightLightRow(false);
                      }
                  });
              }
          } catch (e) {
              this.ErrorCatch(e, "", "error");
          }
      },
      //取消 -- 取消操作，数据还原
      btnClear() {
          this.$confirm("您确定要取消这次改动吗？", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
          })
              .then(() => {
                  this.bChangeFlag = false;
                  this.detailQuery(this.selrow);
              })
              .catch((e) => {});
      },
      //保存 -- 保存新增，修改，删除主表: lab_medgroup 子表: lab_medgroupdetail 操作//
      async btnSave() {
          try {
              if (!this.detailData.medgroupcode) {
                  this.$alert("药物组合代码不能为空！");
                  this.$refs.input0.focus();
                  return false;
              }
              if (!this.detailData.medgroupname) {
                  this.$alert("药物组合名称不能为空！");
                  this.$refs.input2.focus();
                  return false;
              }
              let data = this.$refs.rXTable.getTableData().fullData;
              data.sort((a, b) => {
                  return a.seq - b.seq;
              });
              for (let i = 0, len = data.length; i < len; i++) {
                  let tempseq = (i + 1) * 10;
                  if (tempseq !== data[i].seq) {
                      data[i].seq = tempseq;
                  }
                  data[i].medgroupcode = this.detailData.medgroupcode; //修正新增药物组合后，再次修改药物组合代码导致明细项保存错位。
              }
              const res = await this.$tool.request({
                  url: "LIS/LIS8/LIS821",
                  method: "post",
                  timeout: 600000,
                  data: {
                      action: "lab_medgroup_query_save",
                      utype: this.actionindex,
                      oldinfo: this.tmpdetailData,
                      newinfo: this.detailData,
                      labmedgroupdetail: this.$refs.rXTable.getRecordset(),
                  },
              });
              if (res.errcode == "1") {
                  this.$message.success("保存成功！");
                  this.bChangeFlag = false;
                  if (this.actionindex == "A") {
                      if (this.AddData.indexOf(this.detailData.medgroupcode) == -1) this.AddData.push(this.detailData.medgroupcode);

                      this.$refs.lXTable.insert(this.detailData).then(({ row }) => {
                          this.HightLightRow(row);
                          this.lXTableData.push(row);
                      });
                  } else if (this.actionindex == "M") {
                      if (this.ModData.indexOf(this.detailData.medgroupcode) == -1) this.ModData.push(this.detailData.medgroupcode);
                      await this.SetToTable(this.detailData).then((row) => {
                          this.HightLightRow(row);
                      });
                  } else {
                      this.actionindex = "M";
                  }
              } else {
                  this.ErrorCatch(res.errmsg, "保存失败:", "error");
              }
          } catch (e) {
              this.ErrorCatch(e, "", "error");
          }
      },
      //导出
      btnExport() {
          this.$refs.lXTable.exportCsv({
              filename: "LIS821 抗生素组",
          });
      },
      ErrorCatch(e, msg, type) {
          this.$alert(msg + e, "提示", {
              confirmButtonText: "确定",
              type: type ? type : "error",
          });
      },
      //--------------- 数据改变及其他功能 ---------------//
      //行改变事件
      async CurrentChangeEvent({ row }) {
          if (this.bChangeFlag) {
              this.$refs.lXTable.setCurrentRow(this.selrow);
              return false;
          } else {
              await this.detailQuery(row);
          }
      },
      //保存后不刷新左侧主表,前台赋值。
      SetToTable(obj) {
          return new Promise((s, f) => {
              this.selrow.medgroupcode = obj.medgroupcode;
              this.selrow.medgroupname = obj.medgroupname;
              this.selrow.inputcode = obj.inputcode;
              this.selrow.seq = obj.seq;
              this.selrow.appmethod = obj.appmethod;
              if (obj.groupkind == "1") {
                  this.selrow.groupkind = "补充药敏";
              } else if (obj.groupkind == "9") {
                  this.selrow.groupkind = "仪器转用";
              } else {
                  this.selrow.groupkind = obj.groupkind;
              }
              this.selrow.printbar = obj.printbar;
              this.selrow.panelno = obj.panelno;
              s(this.selrow);
              return;
          });
      },
      // 焦点跳转
      NextFocus(index) {
          var focusIndex = index + 1;
          var that = this;
          if (index < 7) {
              setTimeout(function () {
                  if (index == 4 || index == 6) {
                      that.$refs["input" + index].blur();
                  }
                  if (index != 4) {
                      that.$refs["input" + focusIndex].focus();
                  } else {
                      that.$refs["input" + focusIndex].$el.focus();
                  }
              }, 5);
          } else {
              //表单最后一格 回车 跳转明细表
              this.$refs.rXTable.insertAt(
                  {
                      medgroupcode: this.detailData.medgroupcode,
                      seq: this.autoSeq,
                      etestflag: "0",
                  },
                  -1
              ),
                  this.$refs.rXTable.setActiveRow(this.$refs.rXTable.getTableData().fullData[this.$refs.rXTable.getTableData().fullData.length - 1], "med");
              this.$refs.rXTable.scrollToRow(this.$refs.rXTable.getTableData().fullData[this.$refs.rXTable.getTableData().fullData.length - 1]);
              this.bChangeFlag = true;
          }
      },
      ActiveMethod({ row, column }) {
          if (this.detailData.appmethod == "KB" || this.detailData.appmethod == "Etest") {
              if (column.property == "defaultmic") {
                  if(row.medmethod && row.medmethod =="MIC"){
                      return true;
                  }else{
                      return false;
                  }
              } else if(column.property == "defaultrad"){
                  if(row.medmethod && row.medmethod =="MIC"){
                      return false;
                  }else{
                      return true;
                  }
              }else return true;
          } else if (this.detailData.appmethod == "MIC") {
              if (column.property == "defaultrad") {
                  if(row.medmethod && (row.medmethod =="KB" || row.medmethod =="Etest")){
                      return true;
                  }else{
                      return false;
                  }
              } else {
                  if(column.property == "defaultmic"){
                      if(row.medmethod && (row.medmethod =="KB" || row.medmethod =="Etest")){
                          return false
                      }else{
                          return true;
                      }
                  }else{
                      return true;
                  }
              }
          } else {
              if (row.defaultmic && column.property == "defaultrad") {
                  row.defaultrad = "";
                  this.$forceUpdate();
                  return false;
              } else if ((row.defaultrad || row.etestflag == "1") && column.property == "defaultmic") {
                  row.defaultmic = "";
                  this.$forceUpdate();
                  return false;
              } else {
                  return true;
              }
          }
      },
      appmethodChange() {
          if (!this.detailData.appmethod) {
              this.etesteditflag = false;
          } else {
              this.etesteditflag = true;
              if (this.detailData.appmethod == "Etest") {
                  if (this.rXTableData.length > 0) {
                      this.rXTableData.forEach(element => {
                          element.etestflag = "1";
                          element.defaultrad = "";
                      });
                  }
              } else {
                  if (this.rXTableData.length > 0) {
                      this.rXTableData.forEach(element => {
                          element.etestflag = "0";
                          if (this.detailData.appmethod == "KB") {
                              element.defaultmic = "";
                          } else if (this.detailData.appmethod == "MIC") {
                              element.defaultrad = "";
                          }
                      });
                  }
              }
          }
          this.HasChange();
      },
      //数据发生改变 -- 按钮禁用/可用切换
      HasChange() {
          this.bChangeFlag = true;
      },
      //获取 抗生素弹窗 行数据
      popGetRow(row) {
          this.tempmed = XEUtils.clone(row.medcode);
          this.labMedRow = row;
          this.bPopLabMed = true;
      },
      //获取输入码
      CreateInputcode() {
          this.detailData.inputcode = this.$pub.CreateInputcode(this.detailData.medgroupname, this, 16);
      },
      //获取pop 组件 hidecode，hidename
      LabMedRowChange(c, v) {
          this.labMedRow.medcode = c;
          this.labMedRow.med = v + "[" + c + "]";
          if (this.tempmed != this.labMedRow.medcode) {
              this.HasChange();
          }
          this.bPopLabMed = false;
          this.$refs.rXTable.setActiveCell(this.labMedRow, "seq");
      },
      LabMedRowChanges(labMedRowitems){
          var ishave = false;
          var rxtablealldata = this.$refs.rXTable.tableData;
          var initdata=[]
          let itemno=1;
          var havename="";
          for(var i=0;i<labMedRowitems.length;i++){
              if(rxtablealldata.length>0){
                  try {
                      rxtablealldata.forEach((item) => {
                          if (item.medcode == labMedRowitems[i].medcode) {
                              ishave = true;
                              //this.$alert("抗生素："+labMedRowitems[i].medname+"已经存在！")
                              //return false;
                              havename=havename+"【"+labMedRowitems[i].medname+"】";
                              throw Error();
                          } else {
                              ishave = false;
                          }
                      });
                  }catch(e){}
              }
              if(ishave){
                  continue;
              }
              let seq=(rxtablealldata.length + itemno ) * 10;
              var addrecord={
                  medcode:labMedRowitems[i].medcode,
                  med:labMedRowitems[i].medname + "[" + labMedRowitems[i].medcode + "]",
                  medgroupcode: this.detailData.medgroupcode,
                  seq:seq,
                  etestflag:"0",
              }
              initdata.push(addrecord);
              itemno++;
          }
          if(havename!=""){
              this.$alert("抗生素："+havename+"已经存在！");
              return false;
          }
          if(initdata.length>0){
              this.labMedRow.medcode = initdata[0].medcode;
              this.labMedRow.med = initdata[0].med;
              if (this.tempmed != this.labMedRow.medcode) {
                  this.HasChange();
              }
              initdata.splice(0, 1);
              this.bPopLabMed = false;
              setTimeout(()=>{
                  this.$refs.rXTable.setActiveCell(this.labMedRow, "seq");
                  this.$refs.rXTable.insertAt(initdata,-1);
              })
          }
      },
      //设置高亮选中行
      async HightLightRow(row) {
          if (!!row) {
              this.$refs.lXTable.setCurrentRow(row);
              await this.detailQuery(row);
          } else {
              this.$refs.lXTable.setCurrentRow(null);
              this.detailData = {};
              this.tmpdetailData = {};
              this.rXTableData = [];
          }
      },
      rEditClosed({ row, column }) {
          if (column.property == "loadresultflag") {
              this.bChangeFlag = true;
          }
      },
      //----------------- class -----------------//
      //左侧主表 class
      lRowClassName({ row, rowIndex }) {
          if (this.AddData.indexOf(row.medgroupcode) > -1) {
              return "row-new";
          }
          if (this.ModData.indexOf(row.medgroupcode) > -1) {
              return "row-modify";
          }
      },
      //右侧子表 class
      rRowClassName({ row, rowIndex }) {
          if (row.stopflag == "1") {
              return "rm-alert";
          }
          if (this.$refs.rXTable.hasRowInsert(row)) {
              return "row-new";
          }
          if (this.$refs.rXTable.hasRowChange(row)) {
              return "row-modify";
          }
      },
      rCellClassName({ column, row }) {
          if (column.property == "medgroupcode") {
              return "col-readonly";
          }
      },
      medmethodChange(row) {
          if (row.medmethod.toUpperCase() == "KB" || row.medmethod.toUpperCase() == "ETEST") row.defaultmic = "";
          if (row.medmethod.toUpperCase() == "MIC") row.defaultrad = "";
          if(row.medmethod.toUpperCase() == "ETEST"){
              row.etestflag = "1"
          }else{
              row.etestflag = "0"
          }
          this.HasChange();
      },
  },
};
</script>

<style scoped>
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
.top-title {
  margin: 0 3px 0 20px;
  font-size: 12px;
}
.top-button {
  right: 5px;
  position: absolute;
  top: 5px;
  display: flex;
  align-items: center;
}
.pagetop {
  width: 100%;
  height: 35px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}
.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
.detailxTable {
}
.detail-operation {
  display: flex;
  padding: 0px 2px 0px 5px;
  margin: 5px 0;
}
/deep/.el-textarea__inner {
  display: block;
  resize: vertical;
  padding: 2px 4px;
}
/deep/ .el-button.is-disabled {
  border: 0px;
  color: grey;
  background-color: #e6e6e6;
  font-weight: normal;
}
/deep/ tr.vxe-body--row.row-modify {
  color: blue;
}
/deep/ tr.vxe-body--row.row-new {
  color: #cc6600;
}
/deep/ .col-readonly {
  background-color: #eeeeee;
}
/deep/.el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}
/deep/.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
  border-color: #000000;
}
/deep/ .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}
.tableStyle tr td {
  padding: 0px 2px 0px 2px;
}
</style>
